<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Template Units For Numerical Applications</title>
<link href="TUNAstyles.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
<style type="text/css">

.cabeza_cell {
  border-left: 1px solid #000000;
  border-right: 1px solid #000000;
  border-bottom: 1px solid #000000;
  border-top: 1px solid #000000;
  font-family: Arial,Helvetica,sans-serif;
  font-size: 11pt;
  background-color: #ffffff;
  font-weight: lighter;
  color: #000000;
  text-decoration: none;
}
</style>

</head><body>
<div>
<table align="center" width="640" border="0" cellspacing="2" cellpadding="5" class="border">
<tr>
 <td class="cabeza_cell"> 

  <font style="font-family: helvetica; color: #000000;" size=4>
    <font style="font-family: helvetica; color: #336699; font-weight=bold" size=5>TUNA</font> :
    <font style="font-family: helvetica; color: #336699; font-weight=bold" size=5>T</font>emplate
    <font style="font-family: helvetica; color: #336699; font-weight=bold" size=5>U</font>nits for
    <font style="font-family: helvetica; color: #336699; font-weight=bold" size=5>N</font>umerical 
    <font style="font-family: helvetica; color: #336699; font-weight=bold" size=5>A</font>pplications
 </font><br>
  
</td>
</tr>

<tr>
<td class="cabeza_cell">
 <span style="font-family: helvetica; color: #336699;">
 Documentation Ver 1.0.0 August 2011 by
 <a href="http://mmc.geofisica.unam.mx/luiggi">Luis M. de la Cruz</a> <br>
 <a href="http://mmc.geofisica.unam.mx"> GMMC </a> -
 <a href="http://www.geofisica.unam.mx/recnat/"> Depto. de Recursos Naturales </a> -
 <a href="http://www.geofisica.unam.mx"> Instituto de Geof&iacute;sica </a> -
 <a href="http://www.unam.mx"> UNAM </a><br>
 </span>
 </td>

</tr>

</table>
</div>
<br>
<!-- Generated by Doxygen 1.7.4 -->
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'Search');
--></script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li id="searchli">
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">Tuna/include/Meshes/NonUniform.hpp</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*------------------------------------------------------------------------</span>
<a name="l00002"></a>00002 <span class="comment"> *  Copyright (C) 2011  Luis M. de la Cruz Salas</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> *  This file is part of TUNA</span>
<a name="l00005"></a>00005 <span class="comment"> *</span>
<a name="l00006"></a>00006 <span class="comment"> *  TUNA is free software: you can redistribute it and/or modify</span>
<a name="l00007"></a>00007 <span class="comment"> *  it under the terms of the GNU General Public License as published by</span>
<a name="l00008"></a>00008 <span class="comment"> *  the Free Software Foundation, either version 3 of the License, or</span>
<a name="l00009"></a>00009 <span class="comment"> *  (at your option) any later version.</span>
<a name="l00010"></a>00010 <span class="comment"> *</span>
<a name="l00011"></a>00011 <span class="comment"> *  TUNA is distributed in the hope that it will be useful,</span>
<a name="l00012"></a>00012 <span class="comment"> *  but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00013"></a>00013 <span class="comment"> *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<a name="l00014"></a>00014 <span class="comment"> *  GNU General Public License for more details.</span>
<a name="l00015"></a>00015 <span class="comment"> *</span>
<a name="l00016"></a>00016 <span class="comment"> *  You should have received a copy of the GNU General Public License</span>
<a name="l00017"></a>00017 <span class="comment"> *  along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<a name="l00018"></a>00018 <span class="comment"> ------------------------------------------------------------------------*/</span>
<a name="l00019"></a>00019 
<a name="l00020"></a>00020 <span class="preprocessor">#ifndef _NONUNIFORM_H_</span>
<a name="l00021"></a>00021 <span class="preprocessor"></span><span class="preprocessor">#define _NONUNIFORM_H_</span>
<a name="l00022"></a>00022 <span class="preprocessor"></span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &quot;Meshes/StructuredMesh.hpp&quot;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;fstream&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;string&gt;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;vector&gt;</span>
<a name="l00028"></a>00028 
<a name="l00029"></a>00029 <span class="keyword">namespace </span>Tuna {
<a name="l00030"></a>00030 
<a name="l00031"></a>00031   <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T, <span class="keywordtype">int</span> Dim&gt; <span class="keyword">class </span>NonUniform;
<a name="l00032"></a>00032 
<a name="l00036"></a>00036   <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
<a name="l00037"></a><a class="code" href="structTuna_1_1Typeinfo_3_01NonUniform_3_01T_00_011_01_4_01_4.html">00037</a>   <span class="keyword">struct </span>Typeinfo &lt;<a class="code" href="classTuna_1_1NonUniform.html" title="Adaptor for NON-uniform structured meshes on rectangular domains.">NonUniform</a>&lt;T, 1&gt; &gt; {
<a name="l00038"></a>00038     <span class="keyword">typedef</span> T prec_t;
<a name="l00039"></a>00039     <span class="keyword">enum</span> { Dim = 1 };
<a name="l00040"></a>00040   };
<a name="l00041"></a>00041 
<a name="l00045"></a>00045   <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
<a name="l00046"></a><a class="code" href="structTuna_1_1Typeinfo_3_01NonUniform_3_01T_00_012_01_4_01_4.html">00046</a>   <span class="keyword">struct </span>Typeinfo &lt;<a class="code" href="classTuna_1_1NonUniform.html" title="Adaptor for NON-uniform structured meshes on rectangular domains.">NonUniform</a>&lt;T, 2&gt; &gt; {
<a name="l00047"></a>00047     <span class="keyword">typedef</span> T prec_t;
<a name="l00048"></a>00048     <span class="keyword">enum</span> { Dim = 2 };
<a name="l00049"></a>00049   };
<a name="l00050"></a>00050 
<a name="l00054"></a>00054   <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
<a name="l00055"></a><a class="code" href="structTuna_1_1Typeinfo_3_01NonUniform_3_01T_00_013_01_4_01_4.html">00055</a>   <span class="keyword">struct </span>Typeinfo &lt;<a class="code" href="classTuna_1_1NonUniform.html" title="Adaptor for NON-uniform structured meshes on rectangular domains.">NonUniform</a>&lt;T, 3&gt; &gt; {
<a name="l00056"></a>00056     <span class="keyword">typedef</span> T prec_t;
<a name="l00057"></a>00057     <span class="keyword">enum</span> { Dim = 3 };
<a name="l00058"></a>00058   };
<a name="l00059"></a>00059 
<a name="l00066"></a>00066 <span class="keyword">template</span>&lt;<span class="keyword">class</span> Tprec, <span class="keywordtype">int</span> Dim&gt;
<a name="l00067"></a><a class="code" href="classTuna_1_1NonUniform.html">00067</a> <span class="keyword">class </span><a class="code" href="classTuna_1_1NonUniform.html" title="Adaptor for NON-uniform structured meshes on rectangular domains.">NonUniform</a> : <span class="keyword">public</span> <a class="code" href="classTuna_1_1StructuredMesh.html" title="General structured meshes on rectangular domains.">StructuredMesh</a>&lt;NonUniform&lt;Tprec, Dim&gt; &gt;  {
<a name="l00068"></a>00068   
<a name="l00069"></a>00069 <span class="comment">// Variables from StructuredMesh classes</span>
<a name="l00070"></a>00070   <span class="keyword">using</span> <a class="code" href="classTuna_1_1StructuredMesh.html" title="General structured meshes on rectangular domains.">StructuredMesh&lt; NonUniform&lt; Tprec, Dim &gt;</a> &gt;<a class="code" href="classTuna_1_1GeneralMesh.html#a8e75bc5cbf29abdbceb95226f1315c26" title="Coordinate arrays.">::xyz</a>; <span class="comment">// this comes from Mesh</span>
<a name="l00071"></a>00071   <span class="keyword">using</span> <a class="code" href="classTuna_1_1StructuredMesh.html" title="General structured meshes on rectangular domains.">StructuredMesh&lt; NonUniform&lt; Tprec, Dim &gt;</a> &gt;<a class="code" href="classTuna_1_1StructuredMesh.html#aea159ef45b6d47b8496b18dca4cdad0d" title="Array of deltas for nonuniform meshes.">::dxyz</a>;
<a name="l00072"></a>00072   <span class="keyword">using</span> <a class="code" href="classTuna_1_1StructuredMesh.html" title="General structured meshes on rectangular domains.">StructuredMesh&lt; NonUniform&lt; Tprec, Dim &gt;</a> &gt;<a class="code" href="classTuna_1_1StructuredMesh.html#a14421bdd2cb5ec4b373c9ef9f41a90ba" title="Array of deltas for faces in FV method.">::dface</a>;
<a name="l00073"></a>00073 
<a name="l00074"></a>00074  <span class="keyword">public</span>:
<a name="l00075"></a>00075 
<a name="l00076"></a>00076   <a class="code" href="classTuna_1_1NonUniform.html" title="Adaptor for NON-uniform structured meshes on rectangular domains.">NonUniform</a>() : <a class="code" href="classTuna_1_1StructuredMesh.html" title="General structured meshes on rectangular domains.">StructuredMesh&lt;NonUniform&lt;Tprec, Dim&gt;</a> &gt;() { }
<a name="l00077"></a>00077   ~<a class="code" href="classTuna_1_1NonUniform.html" title="Adaptor for NON-uniform structured meshes on rectangular domains.">NonUniform</a>() {}
<a name="l00078"></a>00078 
<a name="l00079"></a>00079   <span class="keywordtype">bool</span> print() {
<a name="l00080"></a>00080     std::cout &lt;&lt; <span class="stringliteral">&quot; NonUniform &lt; &quot;</span> &lt;&lt; <a class="code" href="classTuna_1_1GeneralMesh.html#adb1220f6fe8395185eba4973fa2e71e2" title="Dimension of the mesh.">Dim</a> &lt;&lt; <span class="stringliteral">&quot;D &gt; &gt;&quot;</span>
<a name="l00081"></a>00081               &lt;&lt; <span class="stringliteral">&quot;\n +-----+&quot;</span>;
<a name="l00082"></a>00082   }
<a name="l00083"></a>00083 
<a name="l00084"></a>00084   <span class="keyword">template</span>&lt;<span class="keyword">typename</span> Tfunct&gt;
<a name="l00085"></a>00085   <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="classTuna_1_1StructuredMesh.html#af4d4ba6cd39da7f441c26a1514edff6a" title="Function used to calculate the points of the mesh.">calcPoints</a>(Axis_t, Tfunct, Tprec, Tprec, <span class="keywordtype">int</span>);
<a name="l00086"></a>00086   <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="classTuna_1_1NonUniform.html#af858964893e2ce8082c0e34eeb410048" title="Calculate the deltas for non-uniform meshes.">calcDeltas</a>(Axis_t);
<a name="l00087"></a>00087 <span class="keyword">protected</span>:    
<a name="l00088"></a>00088 
<a name="l00089"></a>00089 <span class="keyword">private</span>:
<a name="l00090"></a>00090 
<a name="l00091"></a>00091 };
<a name="l00092"></a>00092   
<a name="l00103"></a>00103 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> Tprec, <span class="keywordtype">int</span> Dim&gt;
<a name="l00104"></a>00104 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> Tfunct&gt;
<a name="l00105"></a>00105 <span class="keyword">inline</span> <span class="keywordtype">bool</span>
<a name="l00106"></a><a class="code" href="classTuna_1_1NonUniform.html#aac1456e847a33b388c47892ec6c82cdf">00106</a> <a class="code" href="classTuna_1_1StructuredMesh.html#af4d4ba6cd39da7f441c26a1514edff6a" title="Function used to calculate the points of the mesh.">NonUniform&lt;Tprec, Dim&gt;::calcPoints</a>(Axis_t a, Tfunct f, 
<a name="l00107"></a>00107                                    Tprec x_1, Tprec x_2, 
<a name="l00108"></a>00108                                    <span class="keywordtype">int</span> num_nodes) 
<a name="l00109"></a>00109 {
<a name="l00110"></a>00110   Tprec delta = 1.0 / (num_nodes - 1); <span class="comment">// in the computational space</span>
<a name="l00111"></a>00111   Tprec fact = x_2 - x_1;              <span class="comment">// in the physical space</span>
<a name="l00112"></a>00112 
<a name="l00113"></a>00113 <span class="comment">// this-&gt;... refers to variables defined in the Mesh class. </span>
<a name="l00114"></a>00114   xyz[a].pop_back(); <span class="comment">// first point  </span>
<a name="l00115"></a>00115   <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 0; i &lt; num_nodes; ++i) 
<a name="l00116"></a>00116     xyz[a].push_back ( x_1 + fact * f(i*delta) ); <span class="comment">// apply the function</span>
<a name="l00117"></a>00117 
<a name="l00118"></a>00118   <span class="keywordflow">return</span> 0;
<a name="l00119"></a>00119 }
<a name="l00120"></a>00120 
<a name="l00121"></a>00121 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> Tprec, <span class="keywordtype">int</span> Dim&gt;
<a name="l00122"></a>00122 <span class="keyword">inline</span> <span class="keywordtype">bool</span>
<a name="l00123"></a><a class="code" href="classTuna_1_1NonUniform.html#af858964893e2ce8082c0e34eeb410048">00123</a> <a class="code" href="classTuna_1_1NonUniform.html#af858964893e2ce8082c0e34eeb410048" title="Calculate the deltas for non-uniform meshes.">NonUniform&lt;Tprec, Dim&gt;::calcDeltas</a>(Axis_t a)
<a name="l00124"></a>00124 {
<a name="l00125"></a>00125   <span class="comment">//       x(i-1)   x(i)    x(i+1)          &lt;--- nodes numeration </span>
<a name="l00126"></a>00126   <span class="comment">//   |     |   i   |   i+1   |           |    </span>
<a name="l00127"></a>00127   <span class="comment">//   o--*--|---*---|----*----|-----*-----o    * - internal volumes</span>
<a name="l00128"></a>00128   <span class="comment">//   |     |&lt;-----&gt;|&lt;-------&gt;|           |    o - boundary volumes</span>
<a name="l00129"></a>00129   <span class="comment">//             /        \                 \    </span>
<a name="l00130"></a>00130   <span class="comment">//     dxyz[a][i]     dxyz[a][i+1]         NOTE: the size of boundary                 </span>
<a name="l00131"></a>00131   <span class="comment">//                                                 volumes is zero</span>
<a name="l00132"></a>00132   <span class="keywordtype">int</span> N = xyz[a].size();      <span class="comment">// Number of nodes</span>
<a name="l00133"></a>00133   dxyz[a].push_back( 0.0 );   <span class="comment">// First delta is zero</span>
<a name="l00134"></a>00134   <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 1; i &lt; N; ++i)
<a name="l00135"></a>00135     dxyz[a].push_back( xyz[a][i] - xyz[a][i-1] );
<a name="l00136"></a>00136   dxyz[a].push_back( 0.0 );    <span class="comment">// Last delta is zero</span>
<a name="l00137"></a>00137 
<a name="l00138"></a>00138 
<a name="l00139"></a>00139   <span class="comment">//       x(i-1)   x(i)    x(i+1)               </span>
<a name="l00140"></a>00140   <span class="comment">//   |     |   i   |   i+1   |           |    </span>
<a name="l00141"></a>00141   <span class="comment">//   o--*--|---*---|----*----|-----*-----o   </span>
<a name="l00142"></a>00142   <span class="comment">//      |      |        |</span>
<a name="l00143"></a>00143   <span class="comment">//      |&lt;----&gt;|&lt;------&gt;|   </span>
<a name="l00144"></a>00144   <span class="comment">//          /       \                 </span>
<a name="l00145"></a>00145   <span class="comment">//   dface[i-1]    dface[i]  </span>
<a name="l00146"></a>00146   <span class="comment">// </span>
<a name="l00147"></a>00147   <span class="comment">// First and last deltas should be multiplied by 0.5, but this factor</span>
<a name="l00148"></a>00148   <span class="comment">// is (should be) taken into account in boundary implementations.</span>
<a name="l00149"></a>00149   <span class="comment">//</span>
<a name="l00150"></a>00150   dface[a].push_back( (xyz[a][1] - xyz[a][0]) * 1.0 );     <span class="comment">// First delta</span>
<a name="l00151"></a>00151   <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i = 1; i &lt; N - 1; ++i)              
<a name="l00152"></a>00152     dface[a].push_back( ( xyz[a][i+1] - xyz[a][i-1] ) * 0.5 );
<a name="l00153"></a>00153   dface[a].push_back( (xyz[a][N-1] - xyz[a][N-2]) * 1.0 ); <span class="comment">// Last delta</span>
<a name="l00154"></a>00154 
<a name="l00155"></a>00155   <span class="keywordflow">return</span> 0;
<a name="l00156"></a>00156 }
<a name="l00157"></a>00157 
<a name="l00158"></a>00158 } <span class="comment">//  Tuna namespace</span>
<a name="l00159"></a>00159  
<a name="l00160"></a>00160 <span class="preprocessor">#endif // _NONUNIFORM_H_</span>
<a name="l00161"></a>00161 <span class="preprocessor"></span>
<a name="l00162"></a>00162 
<a name="l00163"></a>00163 
<a name="l00164"></a>00164 
<a name="l00165"></a>00165 
<a name="l00166"></a>00166 
<a name="l00167"></a>00167 
<a name="l00168"></a>00168 
</pre></div></div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr size="1">
<div align="center">
Last modification: Sun Aug 28 09:57:21 CDT 2011
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&copy; 2011 LMCS-UNAM
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Generated by <a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="top" border="0" height="25"></a> 1.6.1 </div>

